home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE24
/
EX4.C
< prev
Wrap
C/C++ Source or Header
|
1995-07-04
|
2KB
|
57 lines
#include <genstub.c>
#define TIMER1 1 // Callback timer.
#define TIMER2 2 // WM_TIMER timer.
HWND hWndGlobal = 0; // Main window's handle.
// Processes events received by the callback funtion
VOID CALLBACK TimerProc( HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{
TCHAR szBuffer[128];
static int times = 0;
HDC hDC = GetDC( hWndGlobal );
wsprintf( szBuffer, "TIMER1 received %d times. ", ++times );
TextOut( hDC, 0, 0, szBuffer, lstrlen(szBuffer ) );
ReleaseDC( hWndGlobal, hDC );
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg)
{
case WM_CREATE: // Store window handle in global for timer callback.
hWndGlobal = hWnd;
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
case WM_COMMAND: // Process menu items.
switch ( LOWORD( wParam ) )
{
case IDM_TEST: // Set up two timers, one callback timer
{ // and one message-based timer.
SetTimer( hWnd, TIMER1, 500, (TIMERPROC) TimerProc );
SetTimer( hWnd, TIMER2, 1000, NULL );
}
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_TIMER: // Process messages received by the message-based timer.
{
TCHAR szBuffer[128];
static int times = 0;
HDC hDC = GetDC( hWnd );
wsprintf( szBuffer, "TIMER2 received %d times. ", ++times );
TextOut( hDC, 0, 20, szBuffer, lstrlen(szBuffer ) );
ReleaseDC( hWnd, hDC );
}
return 0;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
}
return (NULL);
}